package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.FriendshipRequestSO;

@Entity
@Table(name = "FRIENDSHIP_REQUEST", uniqueConstraints = @UniqueConstraint(columnNames = {"SENDER_ID", "RECEIVER_ID" }))
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class FriendshipRequest extends AbstractBaseModel {

	private static final long serialVersionUID = 1L;
	
	@ManyToOne
    @JoinColumn(name = "SENDER_ID", nullable = false)
	private User sender;
	
	@ManyToOne
    @JoinColumn(name = "RECEIVER_ID", nullable = false)
	private User receiver;
	
	public FriendshipRequestSO convertToServiceObject(String... ignoreProperties) {
		FriendshipRequestSO so = (FriendshipRequestSO) convert(new FriendshipRequestSO(), 
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"sender","receiver"}));
		so.setSender(sender.convertToServiceObject(new String[]{"socialUsers"}));
		so.setReceiver(receiver.convertToServiceObject(new String[]{"socialUsers"}));
		return so;
	}

	public User getSender() {
		return sender;
	}

	public void setSender(User sender) {
		this.sender = sender;
	}

	public User getReceiver() {
		return receiver;
	}

	public void setReceiver(User receiver) {
		this.receiver = receiver;
	}

	@Override
	public String toString() {
		return "FriendshipRequest [sender=" + sender + ", receiver=" + receiver
				+ "]";
	}
	
}
